﻿using System.Web.Mvc;
using System.Web.Routing;

using System.Collections.Generic;
using System.Linq;
using System;

using System.Web;
using NCLCustomerManagement.Common.Constant;

namespace NCLCustomerManagement.UI.Helper
{

    public class AuthenticationRequiredAttribute : AuthorizeAttribute
    {
        #region Public Methods

        public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
        {
            var currentUser = filterContext.HttpContext.Session[Constant.CURRENT_USER];
            bool isLogin = currentUser != null;

            if (!isLogin)
            {
                filterContext.Result = new RedirectToRouteResult(
                        new RouteValueDictionary(
                            new { controller = "User", action = "Login" }));
            }
        }

        #endregion

        
    }
}